package com.ivi.car.module.city.view;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.github.promeg.pinyinhelper.Pinyin;
import com.github.promeg.tinypinyin.lexicons.android.cncity.CnCityDict;
import com.ivi.car.R;
import com.ivi.car.base.BaseActivity;
import com.ivi.car.module.city.presenter.CityPresenter;
import com.ivi.car.module.city.view.util.HotGridView;
import com.ivi.car.module.city.view.util.SideBar;
import com.wm.machine.baselibrary.common.widget.layout.TitleBar;
import com.wm.machine.baselibrary.utils.DensityUtils;

import butterknife.BindView;

/**
 * 选择城市界面
 */

public class CityActivity extends BaseActivity {
    @BindView(R.id.city_title_bar)
    TitleBar cityTitleBar;
    @BindView(R.id.city_list)
    RecyclerView cityList;
    @BindView(R.id.city_dialog)
    TextView cityDialog;
    @BindView(R.id.city_slideBar)
    SideBar citySlideBar;
    private HotGridView gridView;
    private CityPresenter cityPresenter;
    private View headView;
    private final int size = 18;
    private TextView locationCity;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_city;
    }

    @Override
    protected void initView() {
        headView = View.inflate(this, R.layout.head_city_list, null);
        gridView = headView.findViewById(R.id.city_hot_list);
        locationCity = headView.findViewById(R.id.city_location);
        citySlideBar.setTextView(cityDialog);
        cityTitleBar.setTitle("选择城市");
        cityTitleBar.setTitleSize(DensityUtils.dp2px(getApplicationContext(), size));
        cityTitleBar.setTitleColor(Color.WHITE);
        cityTitleBar.setLeftDrawable(R.mipmap.back_icon);
        cityTitleBar.setLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void initData() {
        //初始化汉字转拼音工具类
        Pinyin.init(Pinyin.newConfig().with(CnCityDict.getInstance(getApplicationContext())));
        String cityName = getIntent().getStringExtra("locationCity");
        locationCity.setText(cityName);
        cityPresenter = new CityPresenter(this);
        cityPresenter.showHotCity(gridView);
        cityPresenter.showCityList(cityList, headView, citySlideBar);
    }
}
